<?php use_helper('I18N')?>
<?php if(empty($done)){?>

<?php use_javascript('/sfAssetsLibraryPlugin/js/jquery.Jcrop.js');?>
<?php use_stylesheet('/sfAssetsLibraryPlugin/css/jquery.Jcrop.css');?>
<?php /*@var asset sfAsset*/?>
<form method="POST">
<input type="hidden" name="img_x" id="img_x">

<input type="hidden" name="img_y" id="img_y">

<input type="hidden" name="img_w" id="img_w">

<input type="hidden" name="img_h" id="img_h">
<?php if($sf_params->get('no_width_height_resrection')){?>

<input type="hidden" name="no_width_height_resrection" value="1">
<?php }?>
<?php if($sf_params->get('tinymce')){?>

<input type="hidden" name="tinymce" value="1">
<?php }?>
<input type="submit" value="<?php echo __('Create thumb')?>"/>
</form>

<center>
<?php 
$pathes = $asset->getFilepaths();
$full_path = !empty($pathes['original']) ?  $pathes['original'] : $pathes['full'];
?>
<?php echo image_tag(sfAssetToolkit::_to_web_image_path($full_path),array('id'=>'the_crop'))?>
<script type="text/javascript">
    $('#the_crop').Jcrop({
	  onChange  : function (c) {
		$('#img_x').val(c.x);
		$('#img_y').val(c.y);
		$('#img_w').val(c.w);
		$('#img_h').val(c.h);
	}
<?php if(!$sf_params->get('no_width_height_resrection')){?>
    , minSize   : [<?php echo $w?> , <?php echo $h?>]
	, setSelect : [ <?php echo $w?>, <?php echo $h?>, 100, 100 ]
	, aspectRatio : <?php echo $w?>/<?php echo $h?>
<?php }?>
	});
</script>

</center>



<?php }else{//done?>

    <?php if($sf_params->get('tinymce')){
        
        ?>
    
        <?php use_javascript(str_replace('//','/','/'.sfConfig::get('sf_rich_text_js_dir','/js/tiny_mce').'/tiny_mce.js'));?>
        <?php use_javascript(str_replace('//','/','/'.sfConfig::get('sf_rich_text_js_dir','/js/tiny_mce').'/tiny_mce_popup.js'));?>

        <script type="text/javascript">
            tinyMCEPopup.editor.selection.setContent('<img src="<?php echo image_path($asset->getsfAssetThumbByDim($w,$h)->getWebPath(),true)?>" width="<?php echo $w?>px" height="<?php echo $h?>px" />')
            window.close();
        </script>

    <?php }else{//not timymce?>

        <script type="text/javascript">
        //alert($(window.opener.document).find('.thumb-zone-<?php echo $asset->getId()?> li div.thumb.w-<?php echo $w;?>.w-<?php echo $h;?>').length);
        $(window.opener.document)
        .find('.thumb-div-container.asset-id-<?php echo $asset->getId()?>')
        .load('<?php echo url_for1('sfAsset/ajax_get_thumbs?asset_id='.$asset->getId())?>'
        ,function(){window.close();}
        );
        </script>    
    <?php }?>


<?php }?>